//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.未分类.demo1AND20;

import java.util.HashSet;
import java.util.Set;

public class demo3 {
    public demo3() {
    }

    public static void main(String[] args) {
        System.out.println(lengthOfLongestSubstring("abcdb"));
    }

    public static int lengthOfLongestSubstring(String s) {
        char[] ss = s.toCharArray();
        Set<Character> set = new HashSet();
        int res = 0;
        int left = 0;

        for(int right = 0; right < s.length(); ++right) {
            for(char ch = ss[right]; set.contains(ch); ++left) {
                set.remove(ss[left]);
            }

            set.add(ss[right]);
            res = Math.max(res, right - left + 1);
        }

        return res;
    }
}
